package exercises.Charpter9;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Scanner;


class GenerateChar{
	public char[] gen(){
		char[] ans = {'1','2','3','4','5','6','7','8','9','0'};
		return ans;
	}
}

class AdaptedGenerateChar extends GenerateChar implements Readable{

	int i;
	public AdaptedGenerateChar(int i) {
		this.i = i;
	}

	@Override
	public int read(CharBuffer cb) throws IOException {
		if (this.i-- == 0)
			return -1;
		for (char temp : super.gen()) {
			cb.append(temp);
		}
		if (super.gen().length == 0)
			return -1;
		return 0;
	}
}

public class Sixteen {
	public static void main(String[] args){
		Scanner s = new Scanner(new AdaptedGenerateChar(10));
		while (s.hasNext()) {
			System.out.println(s.next());
			
		}
	}
}
